package configs.labels

import com.google.common.collect.Maps
import com.mes.common.framework.spring.ServiceBeanContext
import com.mes.dubbo.interprovider.control.IDpFunctionProvider
import com.mes.dubbo.interprovider.control.IDpLabelProvider
import com.mes.dubbo.interprovider.control.IPdProductInfoProvider
import com.mes.entity.control.DpFunction
import com.mes.entity.control.DpLabel
import com.mes.entity.control.PdProductInfo
/**
 * Created by xiuyou.xu on 2017/9/21.
 */
String cmd = "CT~~CD,~CC^~CT~\n^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR4,4~SD15^JUS^LRN^CI0^XZ\n~DG000.GRF,03456,036,,:::::::::::::::::::::::::::::::::N07FHFH03E0H0783C001E0V0E0J038,N07FHFC03E0H0781C001C0V0C0J018,N07FHFE03E0H0F81C0H0C0V0E0J038,N07001F03F0H0FC1C001C0V0C0J018,N070H0F03F0H0F83C0H0E0V0E0J038,N070H07037001D81C001C0V0C0J018,N060H0383B801B81C0H0C0V0E0J038,N070H07031801981C001C0H043C0F001F80078C0C01C1807C0,N070H0783B803B83C001E0H0EFE3FE03FE03FEE0E038380FF8,N070H07031C03181C001C0H06FF3FC07FF03FFC1C01C181FFC,N06001E039C03381C0H0C0H0F87E1E0E0F8383E0C01838381E,N07FHFC030C071C1C001C0H0703C0C1C038701C0C01C18700C,N07FHF8038E06381C0H0E0H0E0380E3C038E00E0E03838600E,N07FHFH030606181C001C0H06038061801C600C1C01C186007,N0603C0038E0E381C0H0C0H0E0380E38018E00E0C01838FHFE,N0700F003070C181C001C0H04018041801CC0040C01C187FHF,N0700F803830C383C003E0H0E0380E3803CE00E0E03838FIF,N070038030318181C001C0H06038061801C60041C01C1860,N06003C038398380C001C0H0E0380E18038E00E0E01838E0,N07001C0301901C0C001C0H04018061C018600C0C01C1870,N070H0E0383B8380F00380H0E0380E1E038703E0E03838780E,N070H070301F018078070I06038060F070783C0707C183C1E,N060H0F8380E03803FFE0I0E0380E0FFE03FEE0FHF8383FFC,N070H078300E01801FFC0I040180407FC01FCC07F9C181FF8,N070H03E380E038007F80I0E0380E01F80078E03F383803E0,,::::::::::::::::::::::::::::::::::::~DG001.GRF,01920,020,,::::::::::::::::::::::V040H05FDF80,T03F23FLFE,S01F4150K07E,S0F80F80L03E0,R07C0580N07C40,Q03F20F0P0F80,Q07C01E0P01E0,Q0F80BE0Q038,P05C007F0Q01C,P0FE07FE2FKF80I02F20,P07007FC1FKF80J0780,P07003FC3FKF80J0388,P06001FF7FFDHDF80J01C0,O02E003FIFEB9BF80K0E0,O01C0H07FHFC599F80K060,O01C0I0IFCFACF80K0E2,O01C0I01DFC585F80K060,O03E0J03FEDA7F80K0FE,O01C0K07C185F80K07C,O01C0K0LF80K03C,O01C0K07C001F80K01C,P0E0K0FE23FFB820I038,P070K07F77FIFK070,P0780J0NFC80H0E0,P01C0J07FJFDFE5001C0,P03E00200FKF8FHF80380,P04780P01FF046,Q0DE0Q0FE03C,Q0560P01FC050,Q02E20N023F9380,R0140N01F614,S03E0L03FF8E0,T0150J01FF84,R02020FLF3E0,,::O02E203E0383FFE0H03FF3E03E0,N0150501F0187FFC001FF71E07E0,N03C0H03B038E0J03C003F83E0,O0540071819E0H05E1C5D1985E0,P07E0E3E39E0H03E3E3F39AEE0,Q079F5E19E0J01C0719F9E0,O0IFB80E38F80I03E0FB8F8E0,O05F878051815540H0H591851C0,O020J020H020J0202,,::::::::::::::::::::::::::^XA\n^MMT\n^PW480\n^LL0304\n^LS0\n^FT192,96^XG000.GRF,1,1^FS\n^FT32,128^XG001.GRF,1,1^FS\n^FT308,105^A0N,34,33^FH\\^FD9112^FS\n^FT61,267^A0N,23,24^FH\\^FDICCID:89860617020032123766^FS\n^FT219,106^A0N,23,24^FH\\^FD2624^FS\n^FT219,146^A0N,23,24^FH\\^FD0000000075204X^FS\n^FT219,186^A0N,23,24^FH\\^FD545245003^FS\n^FT219,227^A0N,23,24^FH\\^FD1117171A04000004^FS\n^BY78,78^FT64,215^BXN,3,200,0,0,1,~\n^FH\\^FD[)>06Y0000000075204XP2623815812V545245003T1117171A04000004^FS\n^PQ1,0,1,Y^XZ\n^XA^ID000.GRF^FS^XZ\n^XA^ID001.GRF^FS^XZ";

String labelTypeId = "HF6320D1D39314F6C9F60A12429AFFA26"
IPdProductInfoProvider pdProductInfoProvider = (IPdProductInfoProvider) ServiceBeanContext.getInstance().getBean("pdProductInfoProvider")
PdProductInfo pdProductInfo = pdProductInfoProvider.findById(pdProductInfoId)
if(pdProductInfo!=null) {
    String pdId = pdProductInfo.getPdId()
    IDpLabelProvider dpLabelProvider = (IDpLabelProvider) ServiceBeanContext.getInstance().getBean("dpLabelProvider")
    Map<String, Object> map = Maps.newHashMap()
    map.put("pdId", pdId)
    List<DpLabel> dpLabels = dpLabelProvider.findByMap(map)
    if(dpLabels!=null&&!dpLabels.isEmpty()) {
        String template = dpLabels.get(0).getTemplateOrder()
        String fnId = dpLabels.get(0).getFunctionId()
        IDpFunctionProvider dpFunctionProvider = (IDpFunctionProvider) ServiceBeanContext.getInstance().getBean("dpFunctionProvider")
        DpFunction fn = dpFunctionProvider.findById(fnId)
        // TODO get cmd from fn and template
        map.clear()
        map.put("template", template)
//        cmd = (String) GroovyUtil.evalScript(fn.getScript(), map)
    }
}

return cmd;